package com.sany.taskmanager.http;

import com.sany.taskmanager.bean.BaseResponse;
import com.sany.taskmanager.bean.ColorBean;
import com.sany.taskmanager.bean.MaterialBean;
import com.sany.taskmanager.bean.TaskInfoBean;
import com.sany.taskmanager.manager.DataManager;

import java.util.List;

import io.reactivex.rxjava3.core.Single;

public class DataRepository {
    private static volatile DataRepository mInstance;
    private final ApiService apiService;

    private DataRepository() {
        this.apiService = ApiClient.getInstance().getApiService();
    }

    public static DataRepository getInstance() {
        if (mInstance == null) {
            synchronized (DataRepository.class) {
                if (mInstance == null) {
                    mInstance = new DataRepository();
                }
            }
        }
        return mInstance;
    }

    /**
     * 登录
     */
    public Single<BaseResponse<String>> login(String userName, String password, String appId, String factoryCode) {
        return apiService.login(userName, password, appId, factoryCode);
    }

    /**
     * 退出登录
     */
    public Single<BaseResponse<Boolean>> logout() {
        return apiService.logout();
    }

    /**
     * 获取大臂颜色列表
     */
    public Single<BaseResponse<List<ColorBean>>> getColorList() {
        return apiService.getColorList();
    }


    /**
     * 获取大臂颜色列表：通过颜色编码过滤
     */
    public Single<BaseResponse<List<ColorBean>>> getColorListByCode(String colorCode) {
        return apiService.getColorListByCode(colorCode);
    }

    /**
     * 获取三一标配颜色
     */
    public Single<BaseResponse<List<ColorBean>>> getSanyColorList() {
        return apiService.getSanyColorList();
    }

    /**
     * 获取已下发的任务列表
     */
    public Single<BaseResponse<List<TaskInfoBean>>> getSendTaskList() {
        return apiService.getSendTaskList(DataManager.getInstance().getFactoryCode());
    }

    /**
     * 获取历史任务任务列表
     */
    public Single<BaseResponse<List<TaskInfoBean>>> getHistoryTaskList() {
        return apiService.getHistoryTaskList(DataManager.getInstance().getFactoryCode());
    }

    /**
     * 下发任务
     */
    public Single<BaseResponse<Boolean>> sendTask(String taskJson) {
        return apiService.sendTask(DataManager.getInstance().getFactoryCode(), taskJson);
    }

    /**
     * 修改任务
     */
    public Single<BaseResponse<Boolean>> modifyTask(String taskId, String materialNum, int colorType, int boomType) {
        return apiService.modifyTask(taskId, materialNum, colorType, boomType);
    }

    /**
     * 取消任务
     */
    public Single<BaseResponse<Boolean>> cancelTask(String taskId) {
        return apiService.cancelTask(taskId);
    }

    /**
     * 根据车型号获取物料清单
     */
    public Single<BaseResponse<List<MaterialBean>>> getMaterialListByCarModelNum(String carModelNum) {
        return apiService.getMaterialListByCarModelNum(carModelNum);
    }
}
